<?php

namespace App\Http\Controllers\Admin\Data;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use App\Response\Response;
use Carbon\Carbon;
use Illuminate\Http\Request;

/**
 * 概览
 * Class SummaryController
 * @package App\Http\Controllers\Web\Data
 */
class SummaryController extends BaseController {

    /**
     * @api {get} /data/summary 数据看板-概览
     * @apiVersion 0.1.0
     * @apiName 数据看板-概览
     * @apiGroup 数据看板
     *
     * @apiParam {string} secret  密钥, 必传
     *
     * @apiSuccessExample 成功响应
    {
        "code": 200,
        "data": {
            "total_data":{
                "register_user_number(总注册用户人数)": 1,
                "gift_money(平台总流水RMB)": 10002,
                "gift_gold(平台总流水金币)": 10002,
                "recharge_money(平台总充值金额)": 10.1,
                "online_recharge_money(平台总在线支付充值金额)": 10.1,
                "admin_recharge_money(平台总后台充值金额)": 10.1,
                "withdraw_money(平台总提现金额)": 23.2,
                "cash_money(平台总现金流)": 10.1,
                "society_stock_number(历史工会数)": 1,
                "society_active_number(活跃工会数)": 1,
                "hall_stock_number(历史厅数)": 1,
                "hall_active_number(活跃厅数)": 1,
                "society_anchor_number(工会主播人数)": 1
                "society_room_gift_money(工会房间流水RMB)": 10002,
                "society_room_gift_gold(工会房间流水金币)": 10002,
                "society_member_gift_money(工会成员流水RMB)": 10002,
                "society_member_gift_gold(工会成员流水金币)": 10002,
                "user_stock_gold(用户存量总额)": 232323,
                "user_stock_profit_gold(用户收益总额)": 232323,
                "user_stock_balance_gold(用户余额)": 232323,
                "user_stock_gift_gold(用户存量礼物数额)": 232323,
                "wait_withdraw_gold(平台待提现)": 232323,
                "mall_profit_gold(平台个性商城收益)": 232323,
                "nobility_profit_gold(平台爵位购买收益)": 232323,
                "radio_protect_profit_gold(平台电台守护收益)": 232323,
                "dispatch_profit_gold(平台派单流水)": 232323,
                "game_total_cost_gold(平台砸蛋游戏总花费)": 232323,
                "game_cat_cost_gold(小猫钓鱼总花费)": 232323,
                "game_tree_cost_gold(幸运树总花费)": 232323,
                "game_virus_cost_gold(病毒大作战总花费)": 232323,
                "game_total_gift_gold(平台砸蛋游戏总产出)": 232323,
                "game_cat_gift_gold(小猫钓鱼总产出)": 232323,
                "game_tree_gift_gold(幸运树总产出)": 232323,
                "game_virus_gift_gold(病毒大作战总产出)": 232323,
                "game_total_stock_gift_gold(平台砸蛋游戏礼物存量)": 232323,
                "blind_box_total_cost_gold(盲盒总花费)": 232323,
                "blind_box_gift_gold(盲盒礼物流水)": 232323,
                "candy_total_number(总糖果数量)": 232323,
                "candy_total_times(总糖果局数)": 232323,
                "candy_backpack_number(背包剩余糖果数量)": 232323,
            },
            "register_user_list(用户注册趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "recharge_money_list(用户充值趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "gift_value_list(平台流水趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "send_gift_value_list(直刷礼物流水趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "withdraw_money_list(提现趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "cash_list(现金流趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "cat_cost_list(小猫钓鱼总花费趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "cat_reward_list(小猫钓鱼总产出趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "candy_list(抢糖果产出礼物价值趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "blind_box_cost_list(盲盒花费趋势)": [
                {
                    "date": "2020-11-01",
                    "value": 31.1
                }
            ],
            "blind_box_reward_list(盲盒产出趋势)": [
                {
                "date": "2020-11-01",
                "value": 31.1
                }
            ]
        }
    }
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 20050,
     *          "message": "errorMsg"
     *      }
     *
     */
    public function index(Request $request) {
        //参数校验
        try {
            $this->validate($request, [
                'secret' => 'required|string',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }
        $inputGameToken = $request->input("secret");

        $curGameToken = app('repo_config')->queryConfig('DATA_SECRET')->value;

        if ($inputGameToken != $curGameToken) {
            throw new BasicException(10001, "令牌不合法");
        }

        $result = app("repo_data_summary")->getSummaryData();

        return Response::sendData($result);
    }

}